<?php

namespace App\Enums;

/**
 * 库存变动类型枚举
 */
enum InvTransType: int
{
    case INBOUND    = 10; // 入库
    case OUTBOUND   = 20; // 出库
    case MOVE       = 30; // 调拨
    case ASSIGN     = 40; // 分配库存
    case LOCK       = 50; // 冻结库存
    case RELEASE    = 60; // 取消分配

    /**
     * name
     *
     * @return string
     */
    public function label(): string
    {
        return match ($this) {
            self::INBOUND   => "入库",
            self::OUTBOUND  => "出库",
            self::MOVE      => "调拨",
            self::ASSIGN    => "分配",
            self::LOCK      => "冻结",
            self::RELEASE   => "取消分配",
        };
    }

    /**
     * 根据值获取名称
     * @param $val
     * @return string
     */
    static function labelBy($val){
        $obj = self::tryFrom((int)$val);
        return $obj ? $obj->label() : '';
    }
}
